﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using SachOnlineLibrary.Public;
/// <summary>
/// Summary description for DangKiBUS
/// </summary>
namespace SachOnlineLibrary.DAL
{
    public class TaiKhoanDAL
    {
        KetNoiDB db;
        public TaiKhoanDAL()
        {
            db = new KetNoiDB();
        }
        public bool TaoTaiKhoan(TaiKhoan kh)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.CommandText = @"insert TaiKhoan values (@TenTK,@MatKhau,0, @Ten,@NgaySinh, @Email,@SoDT,@DiaChi)";       
            cmd.Parameters.AddWithValue("@TenTK", kh.TenTK);
            cmd.Parameters.AddWithValue("@MatKhau", kh.MatKhau);
            cmd.Parameters.AddWithValue("@Quyen", kh.Quyen);
            cmd.Parameters.AddWithValue("@Ten", kh.Ten);
            cmd.Parameters.AddWithValue("@NgaySinh", kh.NgaySinh);
            cmd.Parameters.AddWithValue("@SoDT", kh.SoDT);
            cmd.Parameters.AddWithValue("@Email", kh.Email);
            cmd.Parameters.AddWithValue("@DiaChi", kh.DiaChi);
           
            return db.ExecuteNonQuery(cmd);
        }


        public DataTable LayTaiKhoan(string tentk, string matkhau)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.CommandText = "select * from taikhoan where tentk=@tentk and matkhau=@matkhau";
            cmd.Parameters.Add("@tentk",SqlDbType.VarChar).Value=tentk;
            cmd.Parameters.Add("@matkhau", SqlDbType.VarChar).Value = matkhau;
            return db.ExecuteQuery(cmd);
        }
        public DataTable LayTaiKhoanTheoTen(string tentk)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.CommandText = "select * from taikhoan where tentk=@tentk";
            cmd.Parameters.Add("@tentk", SqlDbType.VarChar).Value = tentk;
            return db.ExecuteQuery(cmd);
        }
        public DataTable LayTaiKhoanTheoID(int tkid)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.CommandText = "select * from taikhoan where tkid=@tkid";
            cmd.Parameters.Add("@tkid", SqlDbType.Int).Value = tkid;
            return db.ExecuteQuery(cmd); 
        }
    }
}